
import { getToken, setToken, removeToken } from '@/utils/auth'
import { login } from '@/api/user'

export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, token) {
      state.token = token // 设置token
      setToken(token)
    },
    // 删除token
    removeToken(state) {
      state.token = ''
      // 删除本地token
      removeToken()
    }
  },
  actions: {
    async userLogin(context, loginForm) {
      const res = await login(loginForm)
      context.commit('setToken', res.data)
    }
  }
}

